<template>
	<div class="SimulateCenter b f22" @click="closeFrames" >
		<el-row>
			<el-col :span="24">
				<h5 class="">任务设置</h5>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="9">
				<el-form :inline="true" :model="taskForm" :rules="taskRule" ref="taskRef">
					<el-form-item label="任务名称" :label-width="90" prop="taskName" label-position="right" class="w91">
						<el-input maxlength="100"
							v-on:input="taskForm.taskName = taskForm.taskName.replace(/[\u4e00-\u9fa5]/gi, '')"
							v-model="taskForm.taskName" placeholder="请输入任务名称" clearable />
					</el-form-item>
				</el-form>
			</el-col>
			<el-col :span="9">
				<el-form-item label="模型文件" :label-width="90"
				:rules="[{ required: true, message: '请上传模型', trigger: 'blur' }]"
				class="w91 pt uploadForm" style="cursor: pointer !important;">
					<el-input style="cursor: pointer !important;" v-model="modelLocalPath" readonly placeholder="请选择模型文件"
						@click="upload" clearable>
						<template #suffix>
							<div @click="upload">
								<plus-btn />
							</div>
						</template>
					</el-input>
				</el-form-item>
				<el-upload class="avatar-uploader" ref="uploadRef" :http-request="uploadRequest"
                            :show-file-list="false">
                        </el-upload>
			</el-col>
			<el-col :span="6">
				<el-button type="primary" class="startbtn mt16" style="margin-left: 80px"
					@click="startCompute">开始仿真</el-button>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="9">
				<el-form-item label="仿真软件" :label-width="90"
				 :rules="[{ required: true, message: '请选择仿真软件', trigger: 'blur' }]"
				 class="w91" prop="simulator">
					<el-select v-model="form.simulator" placeholder="" @change="changeSimulator" clearable class="w100">
						<el-option value="4" label="fastcae" />
						<!-- <el-option value="5" label="openfoam" /> -->
					</el-select>
				</el-form-item>
			</el-col>
			<el-col :span="9">
				<el-form-item label="仿真模块" :label-width="90" class="w91"
				:rules="[{ required: true, message: '请选择仿真模块', trigger: 'blur' }]"
				 prop="simulateModule">
					<el-select v-model="form.simulateModule" placeholder="Heat Transfer" clearable class="w100">
						<el-option v-for="(item, index) in modules" :value="item.id" :label="item.name" />
						<el-option  value="14" label="HeatTransfer(O)" />
					</el-select>
				</el-form-item>
			</el-col>
			<el-col :span="6">
				<el-button style="visibility: hidden" type="primary">Primary</el-button>
			</el-col>
		</el-row>

		<el-row class="mt10">
			<el-col :span="24">
				<h5 class="">参数设置</h5>
			</el-col>
		</el-row>
		<el-row class="mt20">
			<el-col :span="24" class="fx sb">
				<el-form label-position="right" :model="paramTableData" style="width: 100%">
					<el-tabs v-model="activeName" class="tabspg b" style="width: 83%">
						<template :key="index" v-for="(item, index) in groupData">
							<el-tab-pane :lazy="true" :label="item.groupName" :name="index">
								<div class="b">
									<el-row class="">
										<el-col :span="24">
											<template v-if="item.type == '1' || item.type == '3'">
												<input-table @inputTaskName="inputTaskName" :tabIndex="index" :item="item"
													ref="inputTableRef"></input-table>
											</template>
											<template v-else-if="item.type == '0'">
												<normal-table @modifyParentData="modifyParentData" :tabIndex="index"
													:item="item" ref="normalTableRef"></normal-table>
											</template>
											<template v-else-if="item.type == '2' && form.simulator == '4'">
												<div>
													<bind-table @modifyParentData="modifyParentData" :tabIndex="index"
														:item="item" ref="bindTableRef"></bind-table>
												</div>
											</template>
											<template v-else-if="item.type == '2' && form.simulator == '2'">
												<border-table @modifyParentData="modifyParentData" :tabIndex="index"
													:item="item"></border-table>
											</template>
										</el-col>
									</el-row>
								</div>
							</el-tab-pane>
						</template>
					</el-tabs>
				</el-form>
				<div class="h40 fx ac a" style="right: 60px; top: 0">
					<el-button :disabled="isIncremental" type="success" @click="handleAddParams">添加参数行</el-button>
				</div>
			</el-col>
		</el-row>
		<el-row style="margin-top: 30px">
			<el-col :span="24">
				<div>
					<h5 class="">模型显示</h5>
					<div v-loading="modelLoading" element-loading-text="模型加载中..." class="b fx"
						style="border: 1px solid #d0d1d1; padding: 5px; margin-top: 10px; overflow: auto">
						<div>
							<nodeTreeVue ref="nodeTreeVueDom" />
						</div>
						<div id="modelPreview" class="modelBox">
							<canvas id="viewer"></canvas>
						</div>
					</div>
				</div>
				<div></div>
			</el-col>
		</el-row>

		<!-- 展示弹窗开始 -->
		<el-dialog :destroy-on-close="true" v-model="dialogFormVisible" title="参数附加" width="90%" top="8vh"
			@open="openedCallBack" @close="closeCallBack">
			<div>
				<div class="bb pd30 fx" style="height: 634px">
					<el-row class="b">
						<el-col :span="18">
							<div v-loading="subModelLoading" element-loading-text="模型加载中...">
								<el-row class="b">
									<el-col :span="8">
										<div>
											<NodeTreeVue :height="634" />
										</div>
									</el-col>
									<el-col :span="16">
										<div class="model">
											<div class="f12 bb pb20 ifc b sb" style="line-height: 1;margin-top: -24px;">
												<div>* 双击可选中目标与对象</div>
												<el-form :model="accuracyForm" label-width="">
													<el-form-item label="选择精度" label-width="80">
														<el-radio-group v-model="accuracyForm.accuracy" class="ml-4">
															<el-radio :label="5" size="large">5位</el-radio>
															<el-radio :label="6" size="large">6位</el-radio>
															<el-radio :label="7" size="large">7位</el-radio>
														</el-radio-group>
													</el-form-item>
												</el-form>

											</div>
											<div id="modelPrivewDom" class="b modelDisplay f1"
												style="background-color: #8c8ca9;margin-top: -30px;">
												<canvas id="modelPrivewViewer"></canvas>
											</div>
										</div>
									</el-col>
								</el-row>
							</div>
						</el-col>
						<el-col :span="6">
							<div class="modelTb">
								<div class="tbTitle" style="user-select: none">选中组件与坐标</div>
								<div class="mt16">
									<el-table :data="tableData" style="width: 100%; height: 600px">
										<el-table-column prop="meshName" label="组件名" />
										<el-table-column prop="coordinate" label="坐标值" />
										<el-table-column prop="entityDim" label="实体类型" v-if="isComsol">
											<template #default="scope">
												<el-select class="m-2" placeholder="Select" size="small"
													v-model="scope.row.entityDim" @change="(e) => {
														selectEntityDim(e, scope.$index, scope.row)
													}
														">
													<el-option v-for="item in meshTypeList" :key="item.value"
														:label="item.label" :value="item.value" />
												</el-select>
											</template>
										</el-table-column>
										<el-table-column label="操作">
											<template #default="scope">
												<el-button size="small" type="danger"
													@click="handleDelete(scope.$index, scope.row)">删除</el-button>
											</template>
										</el-table-column>
									</el-table>
								</div>
							</div>
						</el-col>
					</el-row>
				</div>
				<div class="fx je">
					<div class="ifx">
						<el-checkbox v-model="checkAll" class="mt43 mr20 checkAll" v-show="isCheckAllVisible"
							@change="handleCheckAllChange">全选</el-checkbox>
						<el-button @click="compeleteSelect" class="h34 complete mt43 mr20" type="success">完成</el-button>
					</div>

				</div>
			</div>
		</el-dialog>
		<!-- 展示弹窗结束 -->
	</div>
</template>

<script setup>
import { reactive, ref, onMounted, computed, watch, provide, onErrorCaptured, nextTick } from 'vue'
import axios from 'axios'
import plusBtn from '@/components/plusBtn/Index.vue'
import { getAppList, getAppModuleListByAppId, addSubTask, fastCaeCompute, updateFile ,uOpenfoamCompute} from '../api/simulate'
import { selectAppParamTree } from '../api/setting'
import { ElMessage, ElMessageBox } from 'element-plus'
import { modelPath, modelLocalPath } from '@/utils/modelPath.js'

import StpLoader from '@/v2/engine/StpLoader.js'
import { LoaderSettings } from '@/v2/entity/LoaderSettings'
import NormalTable from '@/components/paramsTable/NormalTable.vue'
import useSidebarStatusStore from '../stores/sidebarContrl'
import BindTable from '@/components/paramsTable/BindTable.vue'
import InputTable from '@/components/paramsTable/InputTable.vue'
import NodeTreeVue from '@/components/paramsTable/NodeTree.vue'
import BorderTable from '@/components/paramsTable/BorderTable.vue'
import { TreeMesh } from '@/v2/entity/TreeMesh'


const checkAll = ref(false)//模型组件全选
// 模型结构的树节点
const nodeTreeVueDom = ref(null)
const isComsol = ref(false)
const currentNodeKey = ref(null) //选中的节点
const modelLoading = ref(false)//模型加载状态
const subModelLoading = ref(false)//弹出窗模型加载状态
let isUpload = false //所用的模型是否是上传的模型
const uploadRef = ref()

const baseUrl = computed(() => {
    return import.meta.env.VITE_APP_BASE_URL
})
//用于提交到后端时把模型的ip地址和端口替换
const localModelUrl = computed(() => {
	return modelPath.value
	/*
	let localUrl = modelPath.value
	if (isUpload) {
		localUrl = replaceHttpLink(modelPath.value, '10.21.31.38', '32133')
	}
	return localUrl*/
})

function replaceHttpLink(url, newIp, newPort) {
	// 匹配IP地址和端口  
	const ipPortRegex = /(https?:\/\/)((\d{0,3}\.){3}\d{1,3}:?\d{1,5})/;
	// 使用正则表达式进行匹配并替换  
	const newUrl = url.replace(ipPortRegex, function (match) {
		// 替换IP地址和端口  
		const ip = newIp.replace(/\./g, '.');
		const port = newPort ? `:${newPort}` : '';
		return match.replace(/(\d{1,3}\.){3}\d{1,3}:?\d{1,5}/, `${ip}${port}`);
	});
	return newUrl;
}

provide('currentNodeKey', currentNodeKey)
const cloneNodeTreeDom = ref(null)// 备份一个dom
const accuracyForm = reactive({
	accuracy: 5
})//精度，默认5位

// 点击滚动到当前模型的位置
const scrollIntoView = (selectObject) => {
	if (nodeTreeVueDom.value.treeDom.el$) {
		cloneNodeTreeDom.value = nodeTreeVueDom.value.treeDom.el$
	}
	const nodes = cloneNodeTreeDom.value.querySelectorAll('.el-tree-node')
	let curNode
	let uuid = selectObject.userData.originalMeshInstance.mesh.uuid
	nodes.forEach((item) => {
		if (item.dataset.key == uuid) {
			curNode = item
			currentNodeKey.value = uuid
		}
	})
	curNode.scrollIntoView({ behavior: 'smooth', block: 'center' })
}
// 点击树结构，对应的mesh高亮
const onClickTreeMeshHL = (nodeID) => {
	if (dialogFormVisible.value) {
		if (stpLoader) {
			stpLoader.onTreeClickMeshHightLight(nodeID)
		}
	} else {
		onMountedstpLoader.onTreeClickMeshHightLight(nodeID)
	}
}
provide('onClickTreeMeshHL', onClickTreeMeshHL)

const form = reactive({
	simulator: '',
	simulateModule: '',
})
const taskForm = reactive({ taskName: '' })
const taskRef = ref(null) // form object
const taskRule = reactive({
	taskName: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }]
})



//通过监听页面左侧栏状态改变页面宽
const sidebarStatusStore = useSidebarStatusStore()
const isCollapse = computed(() => {
	return sidebarStatusStore.isCollapse
})


let stpLoader = null

//监听任务名称表单变化修改表格中的任务名称表单
watch(taskForm, (n, o) => {
	setTaskName()
})
//设置表格中的taskname
function setTaskName() {
	groupData.value.map((item, index) => {
		item.paramDataModel.map((mItem, mIndex) => {
			if (mItem.params) {
				mItem.params.map((pItem, pIndex) => {
					if (item.groupKey == 'JOB' && pItem.key == 'name') {
						pItem.val = taskForm.taskName
					}
				})
			}
		})
	})
}

watch(
	form,
	(n, o) => {
		getAppParamTree()
	},
	{
		deep: true,
	}
)
const facesIndex = ref(null) //绑定选项，区分主面和从面，等于1时是主面，等于2时是从面
//获取子组件传来的参数,主要用于把操作的当前行数传递给父组件
function modifyParentData(data) {
	if (data.facesIndex) {
		facesIndex.value = data.facesIndex
		if (data.facesIndex == 1) {
			tableData.value = groupData.value[activeName.value].paramDataModel[data.crtLine].faces1TableData
		} else if (data.facesIndex == 2) {
			tableData.value = groupData.value[activeName.value].paramDataModel[data.crtLine].faces2TableData
		}
	} else {
		tableData.value = groupData.value[activeName.value].paramDataModel[data.crtLine].tableData
		checkAll.value = groupData.value[activeName.value].paramDataModel[data.crtLine].checkAllMesh
	}
	if (data.crtLine !== undefined && data.dialogFormVisible !== undefined) {
		crtLine.value = data.crtLine
		dialogFormVisible.value = data.dialogFormVisible
	}
}
//设置任务名称
function inputTaskName(data) {
	taskForm.taskName = data.taskName
}
//给“绑定”项设置主面坐标和从面坐标
function setwidgetInfo(data) { }

//模型勾选全选
function handleCheckAllChange(val) {
	console.log('val', val)
}

//关闭所有下拉框
function closeFrames() {
	groupData.value.map((item, index) => {
		item.paramDataModel.map((mItem, mIndex) => {
			if (item.type == 0 || item.type == 1) {
				mItem.params.map((pItem, pIndex) => {
					if (pItem.type == 2 || pItem.type == 1) {
						pItem.frameStatus = false
					}
				})
			}
		})
	})
}
//参数表格数据
let paramTableData = ref([])
function handleClose() { }
//当前tab的新增行的对象
const crtObject = {}
function getParamTableData(item, index) {
	crtObject.meshName = []
	crtObject.coordinate = []
	crtObject.params = []
	item.appParams.map((item, id) => {
		if (item.type == 0) {
			crtObject[item.paramKey] = item.value
		} else if (item.type == 1) {
			crtObject[item.paramKey] = item.valueList
		} else if (item.type == 2) {
			crtObject[item.paramKey] = item.valueMap
		}
	})
	groupData.value[index].paramData = crtObject
	return paramTableData.value
}
//当前要添加选点的行
const crtLine = ref(null)
//添加模型的选点
function addModelPoint(index, faceIndex) {
	dialogFormVisible.value = true
	crtLine.value = index
}
//打开表单的下拉框
function openFrame(item) {
	item.frameStatus = true
}
//删除行数
function handleDeleteParams(index, row, params) {
	ElMessageBox.confirm('你是否确定删除本条数据', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(() => {
			groupData.value[activeName.value].paramDataModel.splice(index, 1)
		})
		.catch(() => { })
}
//设置每行能否添加行
const isIncremental = computed(() => {
	if (groupData.value.length > 0 && (groupData.value[activeName.value].type == 0 || groupData.value[activeName.value].type == 2 || groupData.value[activeName.value].type == 3)) {
		return false
	} else {
		return true
	}
})
//添加参数行
function handleAddParams() {
	groupData.value[activeName.value].paramDataModel.push(JSON.parse(groupData.value[activeName.value].antetype))
}

//上传文件
function uploadRequest(e) {

var formData = new FormData();
//e.target.files 获取fileList对象里的上传的file对象添加到formData里面
formData.append("file", e.file);
let token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6InRlc3RlciIsInVzZXJJZCI6MTQyMzYxNjU0fQ.alyZgfFwavfZysfYwpYXuarY5ZtBFjsyAmTDfdHdu_A'
const headers = {
	'Content-Type': 'multipart/form-data',
	'authorization': token,
	'signature': token
}
console.log('baseUrl', baseUrl.value)
//alert(baseUrl )
axios.post(`${baseUrl.value}/twt/upload`, formData, { headers }
).then(response => {
	form.value.filePath = response.data.message
	console.log('上传成功', response.data);
}).catch(error => {
	console.error('上传失败', error);
});
}

//文件上传调用
function upload() {
	if ((window.chrome && window.chrome.webview) || (window.qt && window.sendObject)) {
		updateFile({}).then((res) => {
			console.log('上传成功', res)
			isUpload = true
			ElMessage({
				message: res.message,
				type: 'success',
			})
			modelPath.value = res.data.fileUrl
			modelLocalPath.value = res.data.path
			showModel()
		})
	}else{
		//浏览器端上传
		uploadRef.value.$el.querySelector('input').click()
	}
}

const tableData = ref([]) //模型的鼠标位置

// 鼠标双击之后的回调
const handleMouseDownTableData = (selectObject, point) => {
	const name = selectObject.userData ? ((form.simulator == 3||form.simulateModule == 14) ? selectObject.userData.originalMeshInstance.node.name : selectObject.userData.originalMeshInstance.mesh.alias) : selectObject.name
	const x = isComsol.value ? point.x / 1000 : point.x
	const y = isComsol.value ? point.y / 1000 : point.y
	const z = isComsol.value ? point.z / 1000 : point.z

	const row = {
		meshName: name,
		coordinate: `x:${x.toFixed(accuracyForm.accuracy)},y:${y.toFixed(accuracyForm.accuracy)},z:${z.toFixed(accuracyForm.accuracy)}`,
		entityDim: meshTypeList[3].value,
	}

	console.log('ro-w', row)
	const tableSize = tableData.value.length
	// meshTypeSelect.value = meshTypeList[3].value
	// meshTypeSelect.label = meshTypeList[3].label
	tableData.value.push(row)

	// 设置select值
	const tableRow = tableData.value[tableSize]
	console.log('tableRow', tableRow)
	// tableRow.meshTypeSelect.value = meshTypeList[3].value
	// tableRow.meshTypeSelect.label = meshTypeList[3].label
}

// 删除模型表格数据
const handleDelete = (index, row) => {
	tableData.value.splice(index, 1)
}
// 模型预览关闭的时候删掉canvas
const closeCallBack = () => {
	if (onMountedSetting.value) {
		onMountedSetting.value.callback.onMeshDbClick = scrollIntoView
		onMountedstpLoader.reloadTreeNode()
		stpLoader = null
	}

}
//完成选点
function compeleteSelect() {
	let meshName = []
	let coordinate = []
	let entityDimArr = []
	tableData.value.map((item, index) => {
		meshName.push(item.meshName)
		coordinate.push(coordinateFormat(item.coordinate))
		if (isComsol) {
			entityDimArr.push(item.entityDim)
		}
	})
	if (groupData.value[activeName.value].type == 0 || groupData.value[activeName.value].type == 1) {
		if (isComsol) {
			groupData.value[activeName.value].paramDataModel[crtLine.value].entityDim = entityDimArr
		}

		groupData.value[activeName.value].paramDataModel[crtLine.value].meshName = meshName
		groupData.value[activeName.value].paramDataModel[crtLine.value].coordinate = coordinate
		groupData.value[activeName.value].paramDataModel[crtLine.value].tableData = tableData.value
		groupData.value[activeName.value].paramDataModel[crtLine.value].checkAllMesh = checkAll.value
	} else if (groupData.value[activeName.value].type == 2) {
		//区分主面和从面
		if (facesIndex.value == 1) {
			groupData.value[activeName.value].paramDataModel[crtLine.value].faces1Widget.meshName = meshName[0]
			groupData.value[activeName.value].paramDataModel[crtLine.value].faces1Widget.coordinate = coordinate[0]
		} else if (facesIndex.value == 2) {
			groupData.value[activeName.value].paramDataModel[crtLine.value].faces2Widget.meshName = meshName[0]
			groupData.value[activeName.value].paramDataModel[crtLine.value].faces2Widget.coordinate = coordinate[0]
		}
		if (isComsol) {
			groupData.value[activeName.value].paramDataModel[crtLine.value].entityDim = entityDimArr
		}
	}
	tableData.value = []
	dialogFormVisible.value = false
}
//格式化坐标点
function coordinateFormat(coordinate) {
	coordinate = coordinate.replace(/x:|y:|z:/g, '')
	let items = coordinate.split(',')
	return items
}
// 附件到模型的打开回调

const onTreeFitCamera = (uuid) => {
	stpLoader.treeFitMeshesCamera(uuid)
}
provide('onTreeFitCamera', onTreeFitCamera)
const openedCallBack = () => {
	if (!modelPath.value) {
		return
	}
	const settings = new LoaderSettings('modelPrivewViewer', 'modelPrivewDom')
	settings.callback.onMeshDbClick = handleMouseDownTableData
	settings.callback.onGetModelNodes = onGetModelNodes
	settings.callback.onChangeNodeIsShowState = onChangeNodeIsShowState
	subModelLoading.value = true
	stpLoader = new StpLoader(modelPath.value, settings, () => { subModelLoading.value = false })
	currentNodeKey.value = null
	if (nodeTreeVueDom.value.treeDom.el$) {
		cloneNodeTreeDom.value = nodeTreeVueDom.value.treeDom.el$
	}
}

const dialogFormVisible = ref(false) //参数附加弹窗控制
const activeName = ref(null)//tab切换当前的激活选项
const groupData = ref([])//分组数据
//获取当前被激活tab的组的信息
const isCheckAllVisible = computed(() => {
	if (groupData.value[activeName.value].groupKey.toUpperCase() == 'MATERIAL' /*&& form.simulateModule == '14'*/ ) {
		return true
	} else {
		return false
	}
})

//获取设置参数列表
function getAppParamTree() {
	let simulator = null
	if (!form.simulator || !form.simulateModule) {
		return
	}
	
	selectAppParamTree( form.simulateModule==14?5:1, form.simulateModule ).then((res) => {
		activeName.value = 0
		//把要在页面绑定的数据整理成一个属性
		res.data.map((item, index) => {
			let object = {
				meshName: [],
				coordinate: [],
				params: [],
				tableData: [],
				checkAllMesh: false//是否全选
			}
			let facesObject = {
				faces1Widget: {
					meshName: '',
					coordinate: '',
					dataMaxLength: '',
					faces1: '',
				},
				faces2Widget: {
					meshName: '',
					coordinate: '',
					dataMaxLength: '',
					faces2: '',
				},
				faces1TableData: [],
				faces2TableData: [],
			}
			if (item.type == 0 || item.type == 1 || item.type == 3) {
				item.labelWidth = 0 //表单label宽度
				item.appParams.map((it, id) => {
					if (it.name.length * 14 + 20 > item.labelWidth) {
						item.labelWidth = it.name.length * 14 + 20 > 110 ? 110 : it.name.length * 14 + 20
					}
				})
				item.appParams.sort((a, b) => a.orderBy - b.orderBy);//排序
				item.appParams.map((it, id) => {
					if (it.paramKey) {
						if (it.type == 0) {
							object.params.push({
								...it,
								//name: it.name,
								val: it.value,
								type: 0,
								key: it.paramKey,
								labelWidth: item.labelWidth,
								dataType: it.dataType,
								disabled: false
							})
						} else if (it.type == 1) {
							object.params.push({
								...it,
								val: '',
								type: 1,
								key: it.paramKey,
								dataModelList: getArrayModel(it.valueList),
								frameStatus: false,
								labelWidth: item.labelWidth,
								disabled: false
							})
						} else if (it.type == 2) {
							object.params.push({
								...it,
								val: '',
								type: 2,
								key: it.paramKey,
								unit: Array.isArray(getModelList(it.valueMap)) ? getModelList(it.valueMap)[0] : {},
								titleList: getTitleList(it.valueMap),
								dataModelList: [Array.isArray(getModelList(it.valueMap)) ? getModelList(it.valueMap)[0] : {}],
								frameStatus: false,
								labelWidth: item.labelWidth,
								disabled: false
							})
						}
					}
					//把任务名称跟作业名称关联起来
				})
				item.paramDataModel = [object]
				item.antetype = JSON.stringify(object)
			} else {
				if (item.appParams.length > 0 && item.appParams[0].dataMaxLength) {
					facesObject.faces1Widget.dataMaxLength = item.appParams[0].dataMaxLength
				} else if (item.appParams.length > 1 && item.appParams[1].dataMaxLength) {
					facesObject.faces2Widget.dataMaxLength = item.appParams[1].dataMaxLength
				}
				item.paramDataModel = [facesObject]
				item.antetype = JSON.stringify(facesObject)
			}
		})
		res.data.sort((a, b) => a.orderBy - b.orderBy);//排序
		console.log('f n l', res.data)
		groupData.value = res.data
	})
}

//获取参数值为list的数据
function getArrayModel(listStr) {
	let arr = JSON.parse(listStr)
	let newArr = []
	if (arr && Array.isArray(arr)) {
		arr.map((item, index) => {
			newArr.push({ p: item })
		})
	}
	return newArr
}


//获取title列表
function getTitleList(mapStr) {
	let obj = null
	let arr = []
	try {
		obj = JSON.parse(mapStr)
		obj.map((item, index) => {
			arr.push(item.title)
		})
	} catch (error) {

	}
	return arr

}


/**
 * 格式化Map类型参数,
 * @param mapStr的格式 ：
 * [{"key":"temperature","title":"温度"},{"key":"density","title":"密度"}]
*/
function getModelList(mapStr) {
	let arr = []
	let mapList = null
	let flag = false
	try {
		mapList = JSON.parse(mapStr)
	} catch (e) {
		flag = true
	}
	if (!Array.isArray(mapList)) {
		flag = true
	}
	if (flag) {
		ElMessage({
			message: 'Map类型参数有误',
			type: 'warning',
		})
		return
	}
	let models = {}
	mapList.map((item, index) => {
		models[item.key] = null
		arr.push(models)
	})
	return arr
}

const isStartSimlateBool = ref(false) //仿真状态
//子组件的ref
const inputTableRef = ref(null)
const normalTableRef = ref(null)
const bindTableRef = ref(null)

//获取数组内某个参数key的值
function getParams(arrayObject, key) {
	let value = null
	arrayObject.map((item, index) => {
		if (item.key == key) {
			value = item.val
		}
	})
	return value
}
//载荷参数组获取某个坐标对应的参数数组
function getProperties(params) {
	let obj = {}
	params.map((item, index) => {
		obj[item.key] = item.val
	})
	return obj
}
//把后端返回的List数据结构转化为对象数组结构
function tansformListData(list) {
	let arr = []
	list.map((item, index) => {
		if (Array.isArray(item.p)) {
			arr.push(item.p)
		} else {
			arr.push(/,/.test(item.p + '') ? item.p.split(',') : item.p)
		}
	})
	return arr
}
//开始仿真
function startCompute() {
	let tips = '' //提示
	let groupIndex = '' //组索引
	let paramIndex = '' //List或Map结构的弹窗
	let rowIndex = '' //行数，用于定位弹窗所在的行数
	console.log('groupData.value', groupData.value)
	//表单验证
	taskRef.value.validate(() => { })
	if (!taskForm.taskName) {
		tips = '任务名称不能为空'
	}

	groupData.value.map((item, index) => {
		if (item.type == '0') {
			item.paramDataModel.map((pmItem, pmIndex) => {
				if ((item.groupKey.toUpperCase() == 'MATERIAL' && pmItem.checkAllMesh === false) || item.groupKey.toUpperCase() != 'MATERIAL') {
					if (pmItem.tableData.length == 0) {
						if (groupIndex === '') {
							groupIndex = index
							rowIndex = pmIndex
						}
						if (!tips) {
							tips = item.groupName + '参数组' + (pmIndex + 1) + '行' + '未选中任何部件'
						}
					}
				}
				pmItem.params.map((it, id) => {
					//不同格式表单的校验
					if (it.type == 0) {
						if (it.val === '' || it.val === undefined) {
							if (groupIndex === '') {
								groupIndex = index
							}
							if (!tips) {
								tips = item.groupName + '参数组' + (pmIndex + 1) + '行' + it.name + '不能为空'
							}
						}

						//大小限制
						if (Number(it.val) > it.dataMaxLength && it.dataType == 0) {
							if (groupIndex === '') {
								groupIndex = index
							}
							if (!tips) {
								tips = item.groupName + '参数组' + (pmIndex + 1) + '行' + it.name + '列表中数值不能大于' + it.dataMaxLength
							}
							if (paramIndex === '') {
								rowIndex = pmIndex
								paramIndex = id
							}
						}

					} else if (it.type == 1) {
						//dataModelList
						it.dataModelList.map((lItem, lIndex) => {
							if (lItem.p === '' || lItem.p === undefined) {
								if (groupIndex === '') {
									groupIndex = index
								}
								if (!tips) {
									tips = item.groupName + '参数组' + (pmIndex + 1) + '行' + it.name + '列表中有数据未填写'
								}
								if (paramIndex === '') {
									rowIndex = pmIndex
									paramIndex = id
								}
							}
							//大小限制
							if (Number(lItem.p) > it.dataMaxLength && it.dataType == 0) {
								if (groupIndex === '') {
									groupIndex = index
								}
								if (!tips) {
									tips = item.groupName + '参数组' + (pmIndex + 1) + '行' + it.name + '列表中数值不能大于' + it.dataMaxLength
								}
								if (paramIndex === '') {
									rowIndex = pmIndex
									paramIndex = id
								}
							}
						})
					} else if (it.type == 2) {
						//map类型
						//dataModelList
						it.dataModelList.map((lItem) => {
							if (lItem === '' || lItem === undefined) {
								if (groupIndex === '') {
									groupIndex = index
								}
								if (!tips) {
									tips = item.groupName + '参数组' + (pmIndex + 1) + '行' + it.name + '表格中有数据未填写'
								}
								if (paramIndex === '') {
									rowIndex = pmIndex
									paramIndex = id
								}
							}
							//大小限制
							if (Number(lItem) > it.dataMaxLength && it.dataType == 0) {
								if (groupIndex === '') {
									groupIndex = index
								}
								if (!tips) {
									tips = item.groupName + '参数组' + (pmIndex + 1) + '行' + it.name + '表格中数值不能大于' + it.dataMaxLength
								}
								if (paramIndex === '') {
									rowIndex = pmIndex
									paramIndex = id
								}
							}
						})
					}
				})
			})
		}

		if (item.type == '1') {
			item.paramDataModel.map((pmItem, pmIndex) => {
				pmItem.params.map((it, id) => {
					if (it.type == 0) {
						if (it.val === '' || it.val === undefined || it.val === null) {
							if (groupIndex === '') {
								groupIndex = index
							}
							if (!tips) {
								tips = item.groupName + '参数组第' + (pmIndex + 1) + '行' + it.name + '不能为空'
							}
							if (it.paramKey === 'dof') {
								if (!tips) {
									tips = '请选择' + it.name
								}
							}
						} else if ((it.paramKey == 'numCpus' || it.paramKey == 'numDomain') && it.val === '0') {
							if (groupIndex === '') {
								groupIndex = index
							}
							if (!tips) {
								tips = item.groupName + '参数组第' + (pmIndex + 1) + '行' + it.name + '不能为0'
							}
						}

						//大小限制
						if (Number(it.val) > it.dataMaxLength && it.dataType == 0) {
							if (groupIndex === '') {
								groupIndex = index
							}
							if (!tips) {
								tips = item.groupName + '参数组' + (pmIndex + 1) + '行' + it.name + '列表中数值不能大于' + it.dataMaxLength
							}
							if (paramIndex === '') {
								rowIndex = pmIndex
								paramIndex = id
							}
						}
					} else if (it.type == 1) {
						//dataModelList
						it.dataModelList.map((lItem) => {
							if (lItem.p === '' || lItem.p === undefined) {
								if (groupIndex === '') {
									groupIndex = index
								}
								if (!tips) {
									tips = item.groupName + '参数组' + it.name + '列表中有数据未填写'
								}
								if (paramIndex === '') {
									rowIndex = pmIndex
									paramIndex = id
								}
							}
							//大小限制
							if (Number(lItem.p) > it.dataMaxLength && it.dataType == 0) {
								if (groupIndex === '') {
									groupIndex = index
								}
								if (!tips) {
									tips = item.groupName + '参数组' + it.name + '列表中数值不能大于' + it.dataMaxLength
								}
								if (paramIndex === '') {
									rowIndex = pmIndex
									paramIndex = id
								}
							}
						})

					} else if (it.type == 2) {
						//map类型
						//dataModelList
						it.dataModelList.map((lItem) => {
							if (lItem === '' || lItem === undefined) {
								if (groupIndex === '') {
									groupIndex = index
								}
								if (!tips) {
									tips = item.groupName + '参数组' + it.name + '表格中有数据未填写'
								}
								if (paramIndex === '') {
									rowIndex = pmIndex
									paramIndex = id
								}
							}
							//大小限制
							if (Number(lItem) > it.dataMaxLength && it.dataType == 0) {
								if (groupIndex === '') {
									groupIndex = index
								}
								if (paramIndex === '') {
									paramIndex = pmIndex
								}
								if (!tips) {
									tips = item.groupName + '参数组' + it.name + '表格中数值不能大于' + it.dataMaxLength
								}
								if (paramIndex === '') {
									rowIndex = pmIndex
									paramIndex = id
								}
							}
						})
					}
				})
			})
		}
		if (item.type == '2') {
			item.paramDataModel.map((pmItem) => {
				if (!pmItem.faces1Widget.coordinate) {
					if (groupIndex === '') {
						groupIndex = index
					}
					if (!tips) {
						tips = form.simulator == '4' ? '请添加主面' : '请添加源边界'
					}
				}
				if (!pmItem.faces2Widget.coordinate) {
					if (groupIndex === '') {
						groupIndex = index
					}
					if (!tips) {
						tips = form.simulator == '4' ? '请添加从面' : '请添加目标边界'
					}
				}
				if (form.simulator == '4') {
					if (pmItem.faces1Widget.faces1 === '' || pmItem.faces1Widget.faces1 === undefined) {
						if (groupIndex === '') {
							groupIndex = index
						}
						if (!tips) {
							tips = '主面名称不能为空'
						}
					}
					if (pmItem.faces2Widget.faces2 === '' || pmItem.faces2Widget.faces2 === undefined) {
						if (groupIndex === '') {
							groupIndex = index
						}
						if (!tips) {
							tips = '从面名称不能为空'
						}
					}
				}

			})
		}
	})
	if (tips) {
		if (groupIndex !== '') {
			activeName.value = groupIndex //- 1
			ElMessage({
				message: tips,
				type: 'error',
			})
		} else {
			ElMessage({
				message: tips,
				type: 'error',
			})
		}
		setTimeout(() => {
			/*页面表单验证开始*/
			if (inputTableRef.value && Array.isArray(inputTableRef.value) && inputTableRef.value.length > 0) {
				inputTableRef.value[0].checkForm()
			}
			if (normalTableRef.value && Array.isArray(normalTableRef.value) && normalTableRef.value.length > 0) {
				normalTableRef.value[0].checkForm()
			}
			if (bindTableRef.value && Array.isArray(bindTableRef.value) && bindTableRef.value.length > 0) {
				bindTableRef.value[0].checkForm()
			}
			/*页面表单验证结束*/
		}, 500)
		return
	}

	//创建子任务
	let { simulator, simulateModule } = form
	
	addSubTask({
		appId: simulator,
		appModuleId: simulateModule,
		taskName: taskForm.taskName
	}).then((res) => {
		form.subTaskId = res.data
		if (form.subTaskId) {
				submitFormData()
		} else {
			ElMessage({
				message: '子任务ID能不能为空',
				type: 'warning',
			})
		}

	})
}

//把表单列表参数放到一个对象中
function getInputParams(arrayObject) {
	let obj = {}
	if (Array.isArray(arrayObject)) {
		arrayObject.map((item, index) => {
			obj[item.key] = item.val
		})
	}
	return obj
}

//从每个参数组中提取每一行数据的参数，得到appParams
function getAppParams(obj) {
	let appParams = []
	obj.paramDataModel.map((item, index) => {
		if (obj.type == '2') {//type==2时特殊处理
			let coordinate = coordinateFormat(item.faces1TableData[0].coordinate)
			let coordinate2 = coordinateFormat(item.faces2TableData[0].coordinate)
			appParams.push({
				coordinate: { x: coordinate[0], y: coordinate[1], z: coordinate[2] },
				coordinate2: { x: coordinate2[0], y: coordinate2[1], z: coordinate2[2] },
			})
		} else {
			if (item.tableData && item.tableData.length > 0) {
				item.tableData.map((tItem, tIndex) => {
					let coordinate = coordinateFormat(tItem.coordinate)
					appParams.push({
						coordinate: { x: coordinate[0], y: coordinate[1], z: coordinate[2] },
						entityDim: tItem.entityDim,
						params: getInputParams(item.params),
					})
				})
			} else {
				appParams.push({
					params: getInputParams(item.params),
				})
			}
		}

	})
	return appParams
}

//FastCAE提交仿真
function submitFormData() {
	let simulateParam = {} //提交仿真的参数
	//参数整理
	groupData.value.map((item, index) => {
		let widgetCount = 0
		//根据不同的type判断参数的key是否需要拼接，type==1时只有一组数据,
		//type==0时有多组数据需要递增，
		//type=2时是“绑定”特殊项，可添加行
		//type=3时可添加行,不能加坐标
		if (item.type == '1') {
			item.paramDataModel[0].params.map((it, id) => {
				//根据参数的type来处理对应得参数值，0=>value,1=>List,2=>Map类型
				if (it.type == 0) {
					simulateParam[item.groupKey + '_' + it.key] = it.val
				} else if (it.type == 1) {
					//数组列表
					simulateParam[item.groupKey + '_' + it.key] = tansformListData(it.dataModelList)
				} else if (it.type == 2) {
					//集合map
					simulateParam[item.groupKey + '_' + it.key] = JSON.stringify(it.dataModelList)
				}
			})
		}
		if (item.type == '3') {
			item.paramDataModel.map((mItem, mIndex) => {

				mItem.params.map((it, id) => {
					//根据参数的type来处理对应得参数值，0=>value,1=>List,2=>Map类型
					if (Array.isArray(simulateParam[item.groupKey + '_' + it.key])) {
						if (it.type == 0) {
							simulateParam[item.groupKey + '_' + it.key].push(it.val)
						} else if (it.type == 1) {
							//数组列表
							simulateParam[item.groupKey + '_' + it.key].push(tansformListData(it.dataModelList))
						} else if (it.type == 2) {
							//集合map
							simulateParam[item.groupKey + '_' + it.key].push(JSON.stringify(it.dataModelList))
						}

					} else {
						simulateParam[item.groupKey + '_' + it.key] = [it.val]
					}

				})
			})
		}
		if (item.type == '2') {
			let type_2_index = 0
			item.paramDataModel.map((it, id) => {
				type_2_index++
				simulateParam['TIE_' + type_2_index] = 'tie' + type_2_index
				simulateParam['ZPARAM_TIE_tie' + type_2_index + '_faces1'] = it.faces1Widget.faces1
				simulateParam['ZPARAM_TIE_tie' + type_2_index + '_faces2'] = it.faces2Widget.faces2
				simulateParam['ZPARAM_TIE_tie' + type_2_index + '_faces1Instances'] = it.faces1Widget.meshName
				simulateParam['ZPARAM_TIE_tie' + type_2_index + '_faces2Instances'] = it.faces2Widget.meshName
				simulateParam['ZPARAM_TIE_tie' + type_2_index + '_face1Coordinate'] = it.faces1Widget.coordinate
				simulateParam['ZPARAM_TIE_tie' + type_2_index + '_face2Coordinate'] = it.faces2Widget.coordinate
			})
		}
		if (item.type == '0') {
			item.paramDataModel.map((it, id) => {

				if (item.groupKey.toUpperCase() == 'MATERIAL' && it.checkAllMesh) {
					widgetCount++
					simulateParam[item.groupKey + '_' + widgetCount] = item.groupKey.toLowerCase() + widgetCount
					simulateParam['ZPARAM_' + item.groupKey + '_' + item.groupKey.toLowerCase() + widgetCount + '_checkAllMesh'] = it.checkAllMesh
					it.params.map((itemPrm, indexPrm) => {
						let paramKey = null
						if (item.groupKey == 'ZMATERIAL') {
							paramKey = item.groupKey + '_' + item.groupKey.toLowerCase() + widgetCount + '_' + itemPrm.key
						} else {
							paramKey = 'ZPARAM_' + item.groupKey + '_' + item.groupKey.toLowerCase() + widgetCount + '_' + itemPrm.key
						}
						//根据参数的type来处理对应得参数值，0=>value,1=>List,2=>Map类型
						if (itemPrm.type == 0) {
							simulateParam[paramKey] = itemPrm.val
						} else if (itemPrm.type == 1) {
							//数组列表
							simulateParam[paramKey] = tansformListData(itemPrm.dataModelList)
						} else if (itemPrm.type == 2) {
							console.log('itemPrm', itemPrm)
							//集合map
							simulateParam[paramKey] = itemPrm.dataModelList
						}
					})
				} else {
					it.tableData.map((meshItem, meshIndex) => {
						widgetCount++
						console.log('meshIndex', item.groupKey + '_' + widgetCount)
						simulateParam[item.groupKey + '_' + widgetCount] = item.groupKey.toLowerCase() + widgetCount
						simulateParam['ZPARAM_' + item.groupKey + '_' + item.groupKey.toLowerCase() + widgetCount + '_partname'] = meshItem.meshName
						simulateParam['ZPARAM_' + item.groupKey + '_' + item.groupKey.toLowerCase() + widgetCount + '_coordinate_' + meshItem.meshName] = coordinateFormat(
							meshItem.coordinate
						)
						it.params.map((itemPrm, indexPrm) => {
							let paramKey = null
							if (item.groupKey == 'ZMATERIAL') {
								paramKey = item.groupKey + '_' + item.groupKey.toLowerCase() + widgetCount + '_' + itemPrm.key
							} else {
								paramKey = 'ZPARAM_' + item.groupKey + '_' + item.groupKey.toLowerCase() + widgetCount + '_' + itemPrm.key
							}
							//根据参数的type来处理对应得参数值，0=>value,1=>List,2=>Map类型
							if (itemPrm.type == 0) {
								simulateParam[paramKey] = itemPrm.val
							} else if (itemPrm.type == 1) {
								//数组列表
								simulateParam[paramKey] = tansformListData(itemPrm.dataModelList)
							} else if (itemPrm.type == 2) {
								console.log('itemPrm', itemPrm)
								//集合map
								simulateParam[paramKey] = itemPrm.dataModelList
							}
						})
					})
				}

			})
		}
	})

	simulateParam['PATH_stpPath'] = localModelUrl.value//modelPath.value
	simulateParam['partNum'] = window.meshLength

	console.log('simulateParam', simulateParam)
	console.log('simulateParam', JSON.stringify(simulateParam))

	let { simulator, simulateModule, subTaskId } = form
	let requestData = {
		appId: simulator,
		taskName: taskForm.taskName,
		appModuleId: simulateModule,
		param: { ...simulateParam },
		subTaskId: subTaskId
	}
	isStartSimlateBool.value = true
	let computeFun = null
	if(simulateModule==14){
		computeFun = uOpenfoamCompute
	}else{
		computeFun = fastCaeCompute
	}
	computeFun(requestData)
		.then((res) => {
			isStartSimlateBool.value = false
			ElMessage({
				message: '提交仿真成功',
				type: 'success',
			})
		})
		.catch((err) => {
			isStartSimlateBool.value = false
			ElMessage({
				message: '仿真失败',
				type: 'error',
			})
		})
}

// 仿真软件重新选择时，重新获取一次仿真模块的数据
const changeSimulator = (val) => {
	console.log('val',val)
	isComsol.value = val === '2'
	if (!val) return
	getAppModules(val)
}

const appList = ref([]) //软件列表
//获取仿真软件列表
function getRemoteAppList() {
	form.simulator = '4'
	getAppModules(1)
}
const modules = ref([]) //仿真模块
//获取仿真模块
function getAppModules(id) {
	//id = 
	getAppModuleListByAppId(id==4?1:id).then((res) => {
		modules.value = res.data
		if (Array.isArray(res.data) && res.data.length > 0) {
			form.simulateModule = res.data[0].id
		}
		// getAppParamTree()
	})
}
// 模型节点
const ModelNodes = ref([])
provide('ModelNodes', ModelNodes)
// 显示隐藏节点修改icon
const onChangeNodeIsShowState = (node, bool, treeNode) => {
	const uuid = node.userData.originalMeshInstance.mesh.uuid
	const visible = bool
	processChangeNodesVisible(ModelNodes.value, uuid, visible);
	if (treeNode instanceof TreeMesh) {
		processModelNodesParentTypeMesh(treeNode)
	} else {
		processModelNodesParentType(treeNode, bool)
	}
	ModelNodes.value = [...ModelNodes.value]
}
// 非mesh递归修改节点的父节点icon状态
const processModelNodesParentType = (treeNode, bool) => {
	if (treeNode.parent) {
		const children = treeNode.parent.children
		const childuuid = treeNode.uuid;
		processChangeNodesVisible(ModelNodes.value, childuuid, bool)
		const uuid = treeNode.parent.uuid
		let visibleNum = 0
		children.forEach((item) => {
			if (item.visible === false) {
				visibleNum++
			}
		})
		const visible = visibleNum === children.length ? false : true
		processChangeNodesVisible(ModelNodes.value, uuid, visible)
		processModelNodesParentType(treeNode.parent, bool)
	} else {
		const children = treeNode.children
		processChangeNodesVisibleType(children, bool)
		const uuid = treeNode.uuid
		processChangeNodesVisible(ModelNodes.value, uuid, bool)
	}
}
// 修改非mesh的visible状态
const processChangeNodesVisibleType = (treeNodes, bool) => {
	treeNodes.forEach((item) => {
		if (item.children && item.children.length > 0) {
			item.visible = bool
			processChangeNodesVisibleType(item.children, bool)
		} else {
			item.visible = bool
		}
	})
}
// mesh递归修改节点的父节点icon状态
const processModelNodesParentTypeMesh = (treeNode) => {
	if (treeNode.parent) {
		const children = treeNode.parent.children
		const uuid = treeNode.parent.uuid
		let visibleNum = 0
		children.forEach((item) => {
			if (item.visible === false) {
				visibleNum++
			}
		})
		const visible = visibleNum === children.length ? false : true
		processChangeNodesVisible(ModelNodes.value, uuid, visible)
		processModelNodesParentTypeMesh(treeNode.parent)
	} else {
		const children = treeNode.children
		const uuid = treeNode.uuid
		let visibleNum = 0
		children.forEach((item) => {
			if (item.visible === false) {
				visibleNum++
			}
		})
		const visible = visibleNum === children.length ? false : true
		processChangeNodesVisible(ModelNodes.value, uuid, visible)
	}
}
// 遍历ModelNodes修改visible状态
const processChangeNodesVisible = (nodes, uuid, visible) => {
	nodes.forEach((item) => {
		if (item.uuid === uuid) {
			item.visible = visible
			// console.log('隐藏的节点',item);
		} else if (item.children && item.children.length > 0) {
			processChangeNodesVisible(item.children, uuid, visible)
		}
	})
}



provide('appForm', form)
// 获取模型节点
const onGetModelNodes = (nodes) => {
	// console.log('nodes', nodes)
	processModelNodes(nodes)
	ModelNodes.value = [nodes]
	// console.log('ModelNodes.value', ModelNodes.value)
}
// 递归处理模型节点数据
const processModelNodes = (nodes) => {
	nodes.visible = true
	nodes.label = nodes.alias
	nodes.children.map((item) => {
		if (item.children) {
			if (item.children.length > 0) {
				item.visible = true
				item.label = item.alias
				processModelNodes(item)
			} else {
				item.label = item.alias
				item.visible = item.visible
			}
		}
	})
}

const onTreeFitClick = (node) => {
	if (stpLoader) {
		stpLoader.treeFitMeshesCamera(node.data)
		return
	}
	onMountedstpLoader.treeFitMeshesCamera(node.data)
}

const onTreeDisplayMeshesClick = (node, bool) => {
	if (stpLoader) {
		console.log('stpLoader', stpLoader);
		stpLoader.treeDisplayMeshes(node.data, bool)
		return
	}
	onMountedstpLoader.treeDisplayMeshes(node.data, bool)
}

// ~ EntityDim 设置
const entityDimSelector = ref('')

const meshTypeList = [
	{
		label: '点',
		value: 0,
	},
	{
		label: '边',
		value: 1,
	},
	{
		label: '边界',
		value: 2,
	},
	{
		label: '域',
		value: 3,
	},
]

const selectEntityDim = (entityDimIndex, tableDataIndex, scope) => {
	console.log('scope', scope)
	tableData.value[tableDataIndex].entityDim = entityDimIndex
	console.log('entityDimSelector', entityDimSelector)
}

provide('onTreeFitClick', onTreeFitClick)
provide('onTreeDisplayMeshesClick', onTreeDisplayMeshesClick)

const onMountedSetting = ref(null)
let onMountedstpLoader = null
//模型展示
function showModel() {
	if (!modelPath.value) {
		return
	}
	onMountedSetting.value = new LoaderSettings('viewer', 'modelPreview')
	onMountedSetting.value.callback.onGetModelNodes = onGetModelNodes
	onMountedSetting.value.callback.onChangeNodeIsShowState = onChangeNodeIsShowState
	onMountedSetting.value.callback.onMeshDbClick = scrollIntoView
	const modelUrl = modelPath.value
	modelLoading.value = true
	onMountedstpLoader = new StpLoader(modelUrl, onMountedSetting.value, () => { modelLoading.value = false })
	console.log('onMountedstpLoader', onMountedstpLoader)
}
onMounted(() => {
	getRemoteAppList()
	showModel()
})

</script>
<style lang="scss">
.el-table td.el-table__cell div {
	overflow: visible;
}

.el-table .cell {
	text-align: center;
}

.paramsDiv .el-form-item__label {
	justify-content: flex-end !important;
}


.fw {
	flex-wrap: wrap;
}

.el-table td.el-table__cell div {
	margin-bottom: 0;
}

.conductionForm .el-form-item__content {
	flex: 0 1 240px;
}

.w228 {
	width: 228px !important;
	flex-shrink: 0;
}

.w100 {
	width: 100% !important;
}

.SimulateCenter {
	min-height: 100%;
	background-color: #fff;
	box-sizing: border-box;
	padding: 27px;
	min-width: 1020px;
	/* max-width: 1200px; */
	margin: 0 auto;
	margin-left: 0;
	width: 100vw;

	.checkAll {
		margin-right: 20px !important;
	}

	.uploadForm input {
		cursor: pointer !important;
	}

	.el-form-item {
		margin-top: 14px;
		margin-bottom: 14px !important;
		margin-right: 10px;
	}

	.el-tabs__content * {
		z-index: 10;
	}

	.el-scrollbar__bar,
	.el-scrollbar__bar.is-vertical>div,
	.el-scrollbar__bar.is-horizontal>div {
		display: none;
	}

	.el-table--border .el-table__inner-wrapper::after,
	.el-table--border::after,
	.el-table--border::before,
	.el-table__inner-wrapper::before {
		content: unset;
		position: static;
	}

	td:first-child>div {
		padding: 0;
	}

	td:first-child>div li {
		display: inline-flex;
		align-items: center;
		width: 100%;
		text-align: center;
		justify-content: center;
	}

	.el-form-item__label {
		line-height: 1.3 !important;
		display: inline-flex;
		align-items: center !important;
	}

	.el-tabs__content * {
		overflow: visible !important;
	}

	.el-tabs__content {
		width: 120%;
		overflow: visible !important;
	}

	.complete {
		width: 100px;
	}

	.el-dialog__close {
		display: inline-flex;
		width: 21px;
		align-items: center;
		justify-content: center;
		height: 21px;
		border-radius: 50%;
		background-color: #f56c6c;
		color: #fff !important;
	}

	.modelDisplay {
		height: calc(100% - 28px);
	}

	.tbTitle {
		font-size: 16px;
		color: rgba(40, 45, 48, 1);
	}

	.model {
		box-sizing: border-box;

		padding-right: 20px;
		padding-bottom: 20px;
		height: 646px;
	}

	.paramsRow>div {
		margin-right: 20px;
	}

	.w91 {
		width: 91%;
	}

	.w63 {
		width: 63%;
	}

	.el-input {
		height: 40px;
	}

	.el-form-item__label {
		height: 40px;
		line-height: 40px;
		justify-content: flex-start;
	}

	.el-tabs__nav-wrap::after {
		visibility: hidden;
	}

	.el-tabs__item {
		padding: 0;
		width: 200px;
	}

	.modelBox {
		width: 726px;
		background-color: #8c8ca9;
		height: 451.89px;
	}

	.modelBox {
		width: 100%;
		background-color: #8c8ca9;
		height: 451.89px;
	}

	th {
		background-color: #f6f9fe !important;
	}
}

.startbtn,
.startbtn:active,
.startbtn:focus {
	width: 120px;
	height: 40px;
	opacity: 1;
	font-size: 14px;
	border-radius: 5px;
	color: #fff;
	background: rgba(0, 84, 254, 1);
}

.startbtn:hover {
	background-color: #3176fc;
}

h5 {
	font-size: 16px;
	font-weight: 400;
}

.dropdowntb {
	height: auto;
	display: inline-block;
	border: 0px solid #dcdfe6;
	box-sizing: border-box;
	padding: 14px;
	left: 35%;
	top: 56px;
	z-index: 10;
	background-color: #fff;

	table {
		border-collapse: collapse;
	}

	th,
	td {
		padding: 10px;
	}
}

.gree {
	width: 90px !important;
	height: 32px !important;
}
</style>
